package com.sky.config;

import com.sky.properties.MinioProperties;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
@EnableConfigurationProperties(MinioProperties.class)
public class MinioConfig {

    @Qualifier("sky.minio-com.sky.properties.MinioProperties")
    @Autowired
    private MinioProperties properties;

    /**
     * 获取 MinioClient
     */
    @Bean
    @ConditionalOnMissingBean
    public MinioClient minioClient() {
        log.info("开始创建阿里云上传文件工具类：{}", properties);
        return MinioClient.builder().endpoint(properties.getEndpoint())
                .credentials(properties.getAccesskey(), properties.getSecretkey())
                .build();
    }
}
